<template>
  <van-swipe :autoplay="4000" :show-indicators="false">
    <van-swipe-item v-for="i in swipeList" :key="i.id" @click="rowClick(i)">
      <div class="item">
        <van-image
          width="100%"
          height="50vw"
          :src="i.url | uri"
        />
        <div class="text">{{ i.text }}</div>
      </div>
    </van-swipe-item>
  </van-swipe>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  data() {
    return {
      swipeList: []
    }
  },
  created() {
    this.banner().then((res) => {
      if (res.data.ok === 1) {
        this.swipeList = res.data.data
      }
    })
  },
  methods: {
    rowClick(data) {
      console.log(data)
      this.$router.push(`/blogdetail/${data.to}`)
    },
    ...mapActions(['banner'])
  }
}
</script>

<style scoped lang="scss">
.van-swipe {
  height: 50vw;
}
.item {
  height: 50vw;
  width: 100%;
  position: relative;
  .text {
    width: 100%;
    position: absolute;
    bottom: 0;
    text-align: center;
    font-size: 12px;
    background-color: rgba(255, 255, 255, 0.5);
    color: #333;
    height: 25px;
    line-height: 25px;
    overflow: hidden;
  }
}
</style>
